-local ubus = require "ubus"
-local bit32 = require "bit32"
+local ubus = require("ubus")
+local bit32 = require("bit32")
local function get_wifi_interfaces()
local conn = ubus.connect()
local ubuslist = conn:objects()
local interfaces = {}
- for _,net in ipairs(ubuslist) do
- if net.find(net,"hostapd.") then
- local ifname = net:gsub("hostapd.", "")
- table.insert(interfaces, ifname);
+ for _, net in ipairs(ubuslist) do
+ if net:find("^hostapd%.") then
+ local ifname = net:gsub("hostapd%.", "")
+ table.insert(interfaces, ifname)
end
end
conn:close()
- return interfaces;
+ return interfaces
end
local function is_ubus_interface(ubus_interfaces, interface)
- for i=1,#ubus_interfaces do
- if ubus_interfaces[i] == interface then return true end
+ for i = 1, #ubus_interfaces do
+ if ubus_interfaces[i] == interface then
+ return true
+ end
end
return false
end
local ubus_interfaces = get_wifi_interfaces()
for _, dev_table in pairs(status) do
- for _, intf in ipairs(dev_table['interfaces']) do
- if is_ubus_interface(ubus_interfaces, intf['ifname']) then
-
+ for _, intf in ipairs(dev_table["interfaces"]) do
+ if is_ubus_interface(ubus_interfaces, intf["ifname"]) then
-- Migrate this to ubus interface once it exposes all interesting labels
- local handle = io.popen("hostapd_cli -i " .. intf['ifname'] .." status")
+ local handle = io.popen("hostapd_cli -i " .. intf["ifname"] .. " status")
local hostapd_status = handle:read("*a")
handle:close()
hostapd["channel"] = value
-- hostapd gives us all bss on the relevant phy, find the one we're interested in
elseif string.match(name, "bss%[%d%]") then
- if value == intf['ifname'] then
+ if value == intf["ifname"] then
bss_idx = tonumber(string.match(name, "bss%[(%d)%]"))
end
elseif bss_idx >= 0 then
end
local labels = {
- vif = intf['ifname'],
- ssid = hostapd['ssid'],
- bssid = hostapd['bssid'],
- encryption = intf['config']['encryption'], -- In a mixed scenario it would be good to know if A or B was used
- frequency = hostapd['freq'],
- channel = hostapd['channel'],
+ vif = intf["ifname"],
+ ssid = hostapd["ssid"],
+ bssid = hostapd["bssid"],
+ encryption = intf["config"]["encryption"], -- In a mixed scenario it would be good to know if A or B was used
+ frequency = hostapd["freq"],
+ channel = hostapd["channel"],
}
table.insert(interfaces, labels)
metric_hostapd_station_flag_short_preamble(labels, flags["SHORT_PREAMBLE"] and 1 or 0)
metric_hostapd_station_flag_ht(labels, flags["HT"] and 1 or 0)
- metric_hostapd_station_flag_vht(labels, flags["VHT"]and 1 or 0)
+ metric_hostapd_station_flag_vht(labels, flags["VHT"] and 1 or 0)
metric_hostapd_station_flag_he(labels, flags["HE"] and 1 or 0)
metric_hostapd_station_flag_wmm(labels, flags["WMM"] and 1 or 0)
end
for _, labels in ipairs(get_wifi_interface_labels()) do
- local vif = labels['vif']
- local handle = io.popen("hostapd_cli -i " .. vif .." all_sta")
+ local vif = labels["vif"]
+ local handle = io.popen("hostapd_cli -i " .. vif .. " all_sta")
local all_sta = handle:read("*a")
handle:close()
-local ubus = require "ubus"
-local bit = require "bit"
+local ubus = require("ubus")
+local bit = require("bit")
local function get_wifi_hostapd_interfaces(u)
local ubuslist = u:objects()
local interfaces = {}
- for _,net in ipairs(ubuslist) do
- if net.find(net,"hostapd.") then
+ for _, net in ipairs(ubuslist) do
+ if net:find("^hostapd%.") then
table.insert(interfaces, net)
end
end
local label_station = {
ifname = ifname,
freq = freq,
- station = station
+ station = station,
}
- local rrm_caps_link_measurement = bit.band(bit.lshift(1, 0), vals['rrm'][1]) > 0 and 1 or 0
- local rrm_caps_neighbor_report = bit.band(bit.lshift(1, 1), vals['rrm'][1]) > 0 and 1 or 0
- local rrm_caps_beacon_report_passive = bit.band(bit.lshift(1, 4), vals['rrm'][1]) > 0 and 1 or 0
- local rrm_caps_beacon_report_active = bit.band(bit.lshift(1, 5), vals['rrm'][1]) > 0 and 1 or 0
- local rrm_caps_beacon_report_table = bit.band(bit.lshift(1, 6), vals['rrm'][1]) > 0 and 1 or 0
- local rrm_caps_lci_measurement = bit.band(bit.lshift(1, 4), vals['rrm'][2]) > 0 and 1 or 0
- local rrm_caps_ftm_range_report = bit.band(bit.lshift(1, 2), vals['rrm'][5]) > 0 and 1 or 0
+ local rrm_caps_link_measurement = bit.band(bit.lshift(1, 0), vals["rrm"][1]) > 0 and 1 or 0
+ local rrm_caps_neighbor_report = bit.band(bit.lshift(1, 1), vals["rrm"][1]) > 0 and 1 or 0
+ local rrm_caps_beacon_report_passive = bit.band(bit.lshift(1, 4), vals["rrm"][1]) > 0 and 1 or 0
+ local rrm_caps_beacon_report_active = bit.band(bit.lshift(1, 5), vals["rrm"][1]) > 0 and 1 or 0
+ local rrm_caps_beacon_report_table = bit.band(bit.lshift(1, 6), vals["rrm"][1]) > 0 and 1 or 0
+ local rrm_caps_lci_measurement = bit.band(bit.lshift(1, 4), vals["rrm"][2]) > 0 and 1 or 0
+ local rrm_caps_ftm_range_report = bit.band(bit.lshift(1, 2), vals["rrm"][5]) > 0 and 1 or 0
metric_hostapd_ubus_station_rrm_caps_link_measurement(label_station, rrm_caps_link_measurement)
metric_hostapd_ubus_station_rrm_caps_neighbor_report(label_station, rrm_caps_neighbor_report)
for _, hostapd_int in ipairs(get_wifi_hostapd_interfaces(u)) do
local clients_call = u:call(hostapd_int, "get_clients", {})
- local ifname = hostapd_int:gsub("hostapd.", "")
+ local ifname = hostapd_int:gsub("hostapd%.", "")
- for client, client_table in pairs(clients_call['clients']) do
- evaluate_metrics(ifname, clients_call['freq'], client, client_table)
+ for client, client_table in pairs(clients_call["clients"]) do
+ evaluate_metrics(ifname, clients_call["freq"], client, client_table)
end
end
u:close()